<template>
  <div class="container">
    <el-dialog
      title="是否检查金额"
      :visible.sync="dialog.centerDialogVisible"
      width="30%"
      center
      @close="hideDialog"
      @open="getData"
      :lock-scroll="true"
    >
      <el-image
        v-if="formData.imgUrl"
        :src="formData.imgUrl"
        :preview-src-list="srcList"
      >
      </el-image>
      <p v-else style="text-align: center">暂无核算凭证</p>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" v-if="type == 2" @click="confirm(1)"
          >检查</el-button
        >
        <el-button type="primary" v-else @click="confirm(2)">不检查</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  showNoCheckInfo,
  changeIsCheckMoney,
} from "@/api/returnGoods/returnGoods";
export default {
  props: {
    dialog: Object,
  },
  data() {
    return {
      formData: {
        imgUrl: "",
      },
      type: "",
      srcList: [],
    };
  },

  methods: {
    hideDialog() {
      this.dialog.centerDialogVisible = false;
      this.formData.imgUrl = "";
    },
    //获取数据
    getData() {
      let data = {
        bill_id: this.dialog.id,
      };
      showNoCheckInfo(data).then((res) => {
        if (res.code == 0) {
          this.formData.imgUrl =
            res.data.check_info != null
              ? this.imgHttp + res.data.check_info.file_path
              : "";
          this.srcList[0] =
            res.data.check_info != null
              ? this.imgHttp + res.data.check_info.file_path
              : "";
          this.type = res.data.bill_info.is_check_money;
        }
      });
    },

    //提交
    confirm(type) {
      let data = {
        is_check_money: type,
        ids: this.dialog.id,
      };
      changeIsCheckMoney(data)
        .then((res) => {
          if (res.code == 0) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.hideDialog();
            this.$emit("upData");
          } else {
            this.$message({
              message: res.msg,
              type: "error",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //取消
    cancel() {
      this.hideDialog();
    },
  },
};
</script>